<?php

namespace app\Lib\tool;

class Tags {

    /**
     * html seo tags
     * @param type $data
     * @return string
     */
    public static function html_seo($data) {
        if (IS_SYS_SEO) {
            $result = "<title>" . $data['title'] . "</title>
            <meta name='keywords' content='" . $data['keywords'] . "'>
            <meta name='description' content='" . $data['description'] . "'>";
        } else {
            $result = "<title>" . $data['title'] . "</title>";
        }
        return $result;
    }

    /**
     * 左侧菜单
     * @param type $data
     * @param type $nodes
     */
    public static function html_left_nodes($data, $nodes = []) {



        $nodes_ul = '<ul class="layui-nav layui-nav-tree" lay-shrink="all" id="LAY-system-side-menu" lay-filter="layadmin-system-side-menu">';
        $level_0 = array();
        $level_1 = array();
        $level_2 = array();
        //开始 结束 
        foreach ($data as $v) {
            $level = $v['level'];
            if ($level == 0) {
                array_push($level_0, $v);
            }
            if ($level == 1) {
                array_push($level_1, $v);
            }
            if ($level == 2) {
                array_push($level_2, $v);
            }
        }
        $lv_li = "";
        foreach ($level_0 as $v0) {

            $lv_li .= '<li data-name="' . $v0["module"] . '" class="layui-nav-item"> 
               <a href="javascript:;" lay-tips="' . $v0["name"] . '" lay-direction="3">
                <i class="layui-icon ' . $v0["class"] . '"></i>
                <cite>' . $v0["name"] . '</cite>
              </a>'; 
            $lv_dl = "";
            $lv_dl = '<dl class="layui-nav-child">';
            $lv_dd_1 = "";
            foreach ($level_1 as $v1) {
                //存在下级
                if ($v1['pid'] == $v0['id']) {
                    $lv_dd_1 .= '<dd class="layui-nav-itemed">'; 
                    if(!empty($v1['url']) && $v1['url']!='')
                    { 
                        $lv_dd_1 .='<a lay-href="/' . $v1["url"] . '">' . $v1["name"] . '</a> ';
                    }else{
                        $lv_dd_1 .='<a href="javascript:;">' . $v1["name"] . '</a> ';
                    }
                    //存在下级 
                    $lv_dd_2 = "";
                    foreach ($level_2 as $v2) {
                        if ($v2['pid'] == $v1['id']) { 
                            $lv_dd_2 .='<dl class="layui-nav-child">'; 
                            $lv_dd_2 .=' <dd><a lay-href="/' . $v2["url"] . '">' . $v2["name"] . '</a></dd>';
                            $lv_dd_2 .='</dl>';
                        }
                    } 
                    $lv_dd_1 .=$lv_dd_2 . '</dd>';
                    unset($v1);
                }
            }
            $lv_dl .= $lv_dd_1 . '</dl>';
            $lv_li .=$lv_dl . '</li>';
        }
        $nodes_ul .=$lv_li . '</ul> ';
        return $nodes_ul;
    }

}

?>